<template>
  <form method="post"  @submit.prevent="login">
    <input type="text" name="username" v-model="data.username">
    <input type="text" name="password" v-model="data.password">
    <input type="text" name="modelName"  v-model="data.modelName">
    <input type="submit">
  </form>
</template>

<script>
  import api from '../../axios/api.js'
    export default {
        name: "login",
      data(){//凡是在模板中需要使用的变量都需要在data中定义
        return {data:{
            username:null,
            password:null,
            modelName:'member',
          }
        }
      },
      methods: {
        login: function () {

          var params = new URLSearchParams();
          params.append('username',this.data.username);
          params.append('password',this.data.password);
          params.append('modelName',this.data.modelName);
          api.setDataFromAxios(this.GLOBAL.gloadServer+'/login',params, 'post')//自行封装的axios方法 post get参数需要与mock.js中 参数匹配
            .then(dto => {
               console.log(dto);
               if (dto.code==302){
                 this.$router.push({path:'/memberPage'})
               } else{
                 alert(dto.msg);
               }

            });
        }
      }
    }
</script>

<style scoped>

</style>
